package tree;

import java.util.ArrayList;

public class DeepthErddic {
    public static void main(String[] args) {
        Tree four = new Tree(4, null, null);
        Tree five = new Tree(5, null, null);
        Tree two = new Tree(2, four, five);
        Tree three = new Tree(3, null, null);
        Tree one = new Tree(1,two,three);
        System.out.println("先序");
        deepth(one);
    }

    private static void deepth(Tree one) {
        ArrayList<Tree> trees = new ArrayList<>();
        int point = 0;
        trees.add(one);
        while (trees.size() > point){
            Tree node = trees.get(point);
            if(node.getLeft() != null) trees.add(node.getLeft());
            if(node.getRight() != null) trees.add(node.getRight());
            point++;
            System.out.println(node.getVal());
        }
    }
}
